#! /usr/bin/env node

console.log('翻译');

const url  = 'http://fanyi.youdao.com/openapi.do?keyfrom=toaijf&key=868480929&type=data&doctype=json&version=1.1&q=';
const tit = process.argv[2];  //获取参数
const axios = require('axios');

axios.get(url+encodeURI(tit)).then(ok=>{
    if(ok.data.web){
        const obj = ok.data.web
        let con = ''
        for(let i in obj){
            con += `${obj[i].key}:${obj[i].value}\n\n`
        }
        console.log(con);
    }else{
        console.log(ok.data.translation);
    }
})